package com.kunyi.web.service.log.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kunyi.platform.mybatis.KyPage;
import com.kunyi.platform.tool.util.KyAssertUtil;
import com.kunyi.web.service.log.core.transform.LogSysTransform;
import com.kunyi.web.service.log.entity.domain.LogSys;
import com.kunyi.web.service.log.entity.req.LogSysListReq;
import com.kunyi.web.service.log.entity.resp.LogSysDetailResp;
import com.kunyi.web.service.log.entity.resp.LogSysListResp;
import com.kunyi.web.service.log.mapper.LogSysMapper;
import com.kunyi.web.service.log.service.ILogSysService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName LogOpsServiceImpl
 * @Description ky_log_ops业务实现
 * @Author pengjunjun
 * @Date 2024/3/6 14:30
 * @Version 1.0
 **/
@Service
public class LogSysServiceImpl extends ServiceImpl<LogSysMapper, LogSys> implements ILogSysService {

    @Override
    public PageInfo<LogSysListResp> pageByParam(LogSysListReq req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        List<LogSys> list = baseMapper.listByReq(req);
        return KyPage.page(list,(item) -> LogSysTransform.log2ListResp(item));
    }

    @Override
    public LogSysDetailResp detailById(Long id) {
        KyAssertUtil.isTrue(id.longValue() > 0, "参数格式错误");
        LogSys logOps = baseMapper.selectById(id);
        KyAssertUtil.notNull(logOps, "未找到相应日志！");
        return LogSysTransform.log2DetailResp(logOps);
    }
}
